package com.nxk.modules.core.web;

import com.nxk.modules.exception.ResultEntity;
import com.nxk.modules.utils.FileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一文件上传控制层
 */
@RestController
@RequestMapping("/a/core/file")
public class FileUploadController {

     @Autowired
    private FileUpload fileUpload;

     @PostMapping("/fileUpload")
    public ResultEntity fileUpload(MultipartFile file, HttpServletRequest request) {
        String url = fileUpload.fileUpload(file, request);
        return url == null ? ResultEntity.fail("图片为空!") : ResultEntity.success("上传成功", url);
    }


}
